/*
 * list_data.c
 * Asif Shahidullah
 *
 * Implements common LData functions.
 */

#include <stdio.h>
#include <stdlib.h>

#include "list_data.h"

LData create_LData (int hour, int min, float temp) {
	LData t;
	/* We have these checks to make the program resiliant 
	 * to malloc failure. */
	if (!(t = (LData) malloc (sizeof (struct data_t)))) {
		fprintf (stderr, "Failed to allocate memory for LData.\n");
		return 0;
	}
	t->hour = hour;
	t->min = min;
	t->temp = temp;
	t->ac = 0;
	return t;
}

/* This may seem unecessary, but in the interest of generality
 * and reusability, we have a specific dealloc function - in case
 * an LData object itself contains any allocated memory 
 * constructs. */
void dealloc_LData (LData ldata) {
	free (ldata);
}

int is_LData_match (LData comparator, LData toCompare) {
	/* We only need to compare the hour and minute since
	 * we can assume there are no repeated times. */
	if ((comparator->hour == toCompare->hour) &&
			(comparator->min == toCompare->min))
		return 1;
	else
		return 0;
}
